<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/3/25
  Time: 11:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>登录页</title>
    <link rel="stylesheet" href="./static/layui/css/layui.css">
    <link rel="stylesheet" href="./static/layui/css/style.css">

</head>
<body style="background: url('./static/layui/images/tt.svg') no-repeat; background-size: cover;">
<svg>
    <div class="login-main">
        <header class="layui-elip">登录</header>
        <form class="layui-form">
            <span style="color: red">${msg}</span>
            <div class="layui-input-inline">
                <input type="text" name="account" required lay-verify="required" placeholder="用户名" autocomplete="off"
                       class="layui-input"
                       style="background-color: #f1ebeb55;border-radius: 50px;box-shadow:0 0 4px 4px #e6eee855;"
                       value="admin">
            </div>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="密码"
                       autocomplete="off"
                       class="layui-input"
                       style="background-color: #f1ebeb55;border-radius: 50px;box-shadow:0 0 4px 4px #e6eee855;"
                       value="admin">
            </div>
            <div class="layui-input-inline login-btn">
                <button lay-submit lay-filter="login" style="border-radius: 50px;" class="layui-btn">登录</button>
            </div>
            <hr/>
            <!--<div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-primary">QQ登录</button>
            </div>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-normal">微信登录</button>
            </div>-->
            <p><a href="register.jsp" class="fl">立即注册</a><a href="javascript:;" class="fr">忘记密码？</a></p>

        </form>
    </div>
</svg>

<script src="static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', 'jquery'], function () {

        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;

        form.on('submit(login)', function (data) {
            console.log(data.field);
            $.ajax({
                url: '${pageContext.request.contextPath}/login',
                data: data.field,
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    if (data.code === 1) {
                        layer.msg(data.message + ":即将进入主页", {icon: 1});
                        setTimeout(() => {
                            location.href = "${pageContext.request.contextPath}/main";
                        }, 1500)
                    } else {
                        layer.msg(data.message, {icon: 5});
                    }
                }
            })
            return false;
        })

    });
</script>
</body>
</html>
